﻿using System.Collections.Specialized;
using System.Windows;
using System.Windows.Forms;

using TheSharpFontViewer.Properties;

namespace TheSharpFontViewer
{
    public partial class ManageFolders
    {
        private readonly Settings AppSettings = new Settings();
        public StringCollection AddedFolders = new StringCollection();
        public StringCollection DeletedFolders = new StringCollection();

        public ManageFolders()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (string folder in AppSettings.Folders)
            {
                Folders_ListBox.Items.Add(folder);
            }
        }

        private void AddFolder_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog _FolderBrowserDialog = new FolderBrowserDialog();
            _FolderBrowserDialog.ShowNewFolderButton = false;

            if (_FolderBrowserDialog.ShowDialog() ==
                System.Windows.Forms.DialogResult.OK)
            {
                if (!Folders_ListBox.Items.Contains(_FolderBrowserDialog.SelectedPath))
                {
                    Folders_ListBox.Items.Add(_FolderBrowserDialog.SelectedPath);
                    AppSettings.Folders.Add(_FolderBrowserDialog.SelectedPath);
                    AddedFolders.Add(_FolderBrowserDialog.SelectedPath);
                }
            }
        }

        private void AddFolder_System_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (!Folders_ListBox.Items.Contains("$SystemFolder"))
            {
                Folders_ListBox.Items.Add("$SystemFolder");
                AppSettings.Folders.Add("$SystemFolder");
                AddedFolders.Add("$SystemFolder");
            }
        }

        private void DeleteFolder_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (Folders_ListBox.SelectedItems.Count != 0)
            {
                object _SelectedFolder = Folders_ListBox.SelectedItem;
                Folders_ListBox.Items.Remove(_SelectedFolder);
                AppSettings.Folders.Remove(_SelectedFolder.ToString());
                DeletedFolders.Add(_SelectedFolder.ToString());
            }
        }

        private void Default_button_Click(object sender, RoutedEventArgs e)
        {
            AppSettings.Save();
            DialogResult = true;
            Close();
        }

        private void Cancel_button_Click(object sender, RoutedEventArgs e)
        {
            AddedFolders.Clear();
            DeletedFolders.Clear();
            DialogResult = false;

            Close();
        }
    }
}